<template>
  <view class="page">
    <picker
      mode="date"
      start="1900-01"
      end="2099-12"
      fields="month"
      :value="startDate"
      @change="bindChangeDate"
    >
      <view class="flex align-center">
        <view class="title fw-600 f-s-32">{{ dateNum }}</view>
        <image
          src="https://app-cangshu.oss-rg-china-mainland.aliyuncs.com/asssets/merchant/showBelow.png"
          class="showBelow"
          mode="scaleToFill"
        />
      </view>
    </picker>
  </view>
</template>

<script>
const date = new Date();
const years = [];
const months = [];
for (let i = 1990; i <= date.getFullYear(); i++) {
  years.push(i);
}
for (let i = 1; i <= 12; i++) {
  months.push(i);
}
export default {
  props: {
    name: {
      type: String,
      default: "",
    },
    dateNum: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      years,
      mark: 1,
      year: date.getFullYear(),
      months,
      month: 2,
      startDate: "",
      status: true, // 节流
      value: [9999, 1, 1],
    };
  },
  created() {
    // this.transferData();
  },
  methods: {
    // 限制选择超过结束日期
    validateFutureTime(date) {
      const now = new Date(date);
      const selected = new Date(this.endDate);
      let nowTime = now.getTime(); // 开始日期
      let selectedTime = selected.getTime(); // 结束日期
      let status = false;
      if (selectedTime < nowTime) {
        uni.showToast({ title: "开始日期不能超过结束日期", icon: "none" });
        status = true;
      }
      return status;
    },
    // 限制选择超过开始时间
    validatePastTime(date) {
      const now = new Date(date);
      const selected = new Date(this.startDate);
      let nowTime = now.getTime(); // 结束日期
      let selectedTime = selected.getTime(); // 开始日期
      let status = false;
      if (selectedTime > nowTime) {
        uni.showToast({ title: "结束日期不能早过开始日期", icon: "none" });
        status = true;
      }
      return status;
    },
    // 选择时间
    bindChangeDate(e) {
      this.startDate = e.detail.value;
      this.$emit("getDateData", e.detail.value);
    },

    // 时间格式化
    formatDate(date) {
      const year = date.getFullYear();
      const month = String(date.getMonth() + 1).padStart(2, "0");
      const day = String(date.getDate()).padStart(2, "0");
      return `${year}-${month}-${day}`;
    },
    showPopup() {
      // 打开提示
      this.$refs.popups.open();
    },
    // 传输初始数据
    transferData(value, data) {},
  },
};
</script>

<style scoped lang="scss">
.picker-container {
  height: 200px;
  width: 100%;
  .title {
    color: #272727;
  }
}
.page {
  //   background: #fff;
  .btnList {
    padding: 40rpx 30rpx;
  }
  .pickerList {
    // display: flex;
  }
  .pickerView {
    background: #fff;
  }
}
.btnList,
.sure {
  font-size: 28rpx;
  color: #272727;
}
.op05 {
  opacity: 0.5;
}
.showBelow {
  width: 18rpx;
  height: 9rpx;
  margin-left: 14rpx;
}
.h-100 {
  height: 100rpx;
}
</style>
